﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NativeLibrary;

namespace DriveBeamEditor.Controls.General
{
    public partial class TreeViewEx : TreeView
    {
        public TreeViewEx()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == (int)WindowsMessages.WM_LBUTTONDBLCLK && CheckBoxes)
            {
                var x = m.LParam.ToInt32() & 0xffff;
                var y = (m.LParam.ToInt32() >> 16) & 0xffff;
                var hitTestInfo = HitTest(x, y);

                /* Disallow checking checkboxes on double-click */
                if (hitTestInfo.Node != null && hitTestInfo.Location == TreeViewHitTestLocations.StateImage)
                {
                    m.Result = IntPtr.Zero;
                    return;
                }
            }

            base.WndProc(ref m);
        }
    }
}
